package com.archermind.boc.xml.parser.impl;

import com.archermind.boc.domain.IQ;
import com.thoughtworks.xstream.XStream;

public class IQProcessor extends BaseProcessor {
	private XStream xstream;

	public XStream getXstream() {
		return xstream;
	}

	public void setXstream(XStream xstream) {
		this.xstream = xstream;
	}

	@Override
	public Object parse(String sessionID, String xml) throws Exception {
		IQ result = (IQ) xstream.fromXML(xml);
		result.setSessionID(sessionID);
		if (result.getJingle() != null && result.getJingle().getContent() != null && result.getJingle().getContent().getTransport() != null
				&& result.getJingle().getContent().getTransport().getIp() != null)
			result.getJingle().getContent().getTransport().setIp(sessionID.split("-")[0]);
		return result;
	}

	@Override
	public void doBack(Object object) {
		IQ iq = (IQ) object;
		getDispatch().dispatch(iq);
	}
}
